package storage.statistics;

import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import common.EarthSimSettings;

import storage.beans.Region;

public class MaxTemperatureStatistic extends Statistic {
  private EarthSimSettings settings = EarthSimSettings.getInstance();
  private double temperature;
  private long dateTime;
  private Region region;
  
  public MaxTemperatureStatistic(double temperature, Region region, long dateTime) {
    super(StatisticType.MAX_TEMP);
    this.region = region;
    this.dateTime = dateTime;
    this.temperature = temperature;
  }
  
  public MaxTemperatureStatistic(String value) {
    super(StatisticType.MAX_TEMP, value);
  }

  public String getHtmlString() {
    DecimalFormat decimal = new DecimalFormat("0.0000E00");
    DateFormat date = new SimpleDateFormat("EEE, MMM d, yyyy HH:mm z Z");
    date.setTimeZone(settings.getTimeZone());
    String html = "<b>Max Temperature: </b>" + decimal.format(temperature) +
      "<br>  Cell: "+region.toString() +
      "<br>  Time: "+ date.format(new Date(dateTime));
    ;
    return html;
  }  
  
  public String getStatValues() {
    String values = temperature + SEP + 
                    region.getLongEast() + SEP + 
                    region.getLongWest() + SEP + 
                    region.getLatNorth() + SEP + 
                    region.getLatSouth() + SEP + 
                    dateTime;
    return values;
  }
  
  public double getTemperature() {
    return temperature;
  }
  
  public void setStatValue(String value) {
    String[] values = value.split(SEP);
    temperature = Integer.parseInt(values[0]);
    int longEast = Integer.parseInt(values[1]);
    int longWest = Integer.parseInt(values[2]);
    int latNorth = Integer.parseInt(values[3]);
    int latSouth = Integer.parseInt(values[4]);
    region = new Region(longWest, longEast, latNorth, latSouth);
    dateTime = Long.parseLong(values[5]);    
  }
  
}
